﻿using System.Globalization;
using System.Windows.Data;

namespace VideoTools.Converters
{
    public class EnumCheckedConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
                return null;
            Enum a = (value as Enum);
            bool isCheck = false;
            string[] names = Enum.GetNames(a.GetType());
            try
            {
                int index = -1;

                index = int.Parse((string)parameter);
                if (names[index].Equals(a.ToString()))
                {
                    isCheck = true;
                }
            }
            catch
            {
                //字符串，
                foreach(string name in names)
                {
                    if (name.Equals((string)parameter))
                {
                        isCheck = true;
                    }
                }
                
            }
            return isCheck;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
